# -*- coding: utf-8 -*-
# Created by zhangyanqi on 2018/4/15

"""
给定一个非负整数组成的非空数组，给整数加一。

可以假设整数不包含任何前导零，除了数字0本身。

最高位数字存放在列表的首位。
"""


class Solution:
    def plusOne(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        result = []
        will_add = True
        for index in reversed(range(0, len(digits))):
            value = digits[index]
            if will_add:
                value += 1
            if value == 10:
                if index != 0:
                    digits[index] = value - 10
                    will_add = True
                else:
                    digits[index] = value - 10
                    result.append(1)
                    for m in digits:
                        result.append(m)
                    return result
            else:
                digits[index] = value
                will_add = False
        return digits


if __name__ == "__main__":
    s = Solution()
    l = [9, 9, 9]
    one = s.plusOne(l)
    print(one)
